﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Linq;
using System.Collections.Generic;
using System.Collections.ObjectModel;

using Marking.Dashboard.Infrastructures;
using Marking.Dashboard.Services;

namespace Marking.Dashboard.ViewModels.Stock
{
    public class StockViewModel : ViewModelBase
    {
        #region 依赖服务

        private IStockService _stockService;

        #endregion

        #region 构造方法

        public StockViewModel(IStockService stockService)
        {
            _stockService = stockService;

            this.SalesClothStockColumnChartViewModel = new StockColumnChartViewModel("大货实时库存，总库存（{0:N0}）匹。");
            this.ColouredClothStockColumnChartViewModel = new StockColumnChartViewModel("色布实时库存，总库存（{0:N0}）匹。");
            this.ClothStockColumnChartViewModel = new StockColumnChartViewModel("胚布实时库存，总库存（{0:N0}）匹。");

            this.LoadStockInfos();
        }

        #endregion

        #region 实时库存

        public StockColumnChartViewModel SalesClothStockColumnChartViewModel { get; private set; }

        public StockColumnChartViewModel ColouredClothStockColumnChartViewModel { get; private set; }

        public StockColumnChartViewModel ClothStockColumnChartViewModel { get; private set; }

        private void LoadStockInfos()
        {
            this.LoadSalesClothStockInfos();
            this.LoadColouredClothStockInfos();
            this.LoadClothStockInfos();
        }

        private void LoadSalesClothStockInfos()
        {
            this.SalesClothStockColumnChartViewModel.Clear();

            _stockService.LoadSalesClothStockInfos((stockInfos) =>
            {
                foreach (var item in stockInfos)
                {
                    this.SalesClothStockColumnChartViewModel.Add(item);
                }
            });
        }

        private void LoadColouredClothStockInfos()
        {
            this.ColouredClothStockColumnChartViewModel.Clear();

            _stockService.LoadColouredClothStockInfos((stockInfos) =>
            {
                foreach (var item in stockInfos)
                {
                    this.ColouredClothStockColumnChartViewModel.Add(item);
                }
            });
        }

        private void LoadClothStockInfos()
        {
            this.ClothStockColumnChartViewModel.Clear();

            _stockService.LoadClothStockInfos((stockInfos) =>
            {
                foreach (var item in stockInfos)
                {
                    this.ClothStockColumnChartViewModel.Add(item);
                }
            });
        }

        #endregion
    }
}
